package com.lanjiyin.cloud.admin.rest;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanjiyin.cloud.admin.biz.GateLogBiz;
import com.lanjiyin.cloud.admin.entity.GateLog;
import com.lanjiyin.cloud.common.msg.Result;
import com.lanjiyin.cloud.common.msg.TableRpcResponse;
import com.lanjiyin.cloud.common.rest.BaseController;
import com.lanjiyin.cloud.common.util.Query;

import tk.mybatis.mapper.entity.Example;

@Controller
@RequestMapping("gateLog")
public class GateLogController extends BaseController<GateLogBiz, GateLog> {
	@RequestMapping(value = "/custom/page", method = RequestMethod.GET)
	@ResponseBody
	public Result<TableRpcResponse<GateLog>> page(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		// 获取分页参数
		Query query = new Query(params);
		Example example = new Example(GateLog.class);
		Example.Criteria criteria = example.createCriteria();
		if (query.entrySet().size() > 0) {
			for (Map.Entry<String, Object> entry : query.entrySet()) {
				criteria.andLike(entry.getKey(), "%" + entry.getValue().toString() + "%");
			}
		}
		example.setOrderByClause("id desc");
		Page<Object> result = PageHelper.startPage(query.getPage(), query.getLimit());
		List<GateLog> list = baseBiz.selectByExample(example);
		return new Result<TableRpcResponse<GateLog>>(new TableRpcResponse<GateLog>(result.getTotal(), list));
	}
}
